// pages/share/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    portrait:[
      {img:'../image/list_15_03.png',type:true},{ img: '', type: false },{ img: '', type: false }, 
      { img: '', type: false }, { img: '', type: false }, { img: '', type: false }, { img: '', type: false }
    ],
    second:''
  },
  rule:function(){
    app.navTo('../rule/index')
  },
  //转时间
  uctime: function () {
    let that = this;
    var time = that.data.time;
    let set;
    var t;
    time = time - 1
    if (time > -1) {
      var day = Math.floor(time / 3600 / 24);     //天
      //console.log(day,'------------')
      var hour = Math.floor(time / 3600) % 24;       //时
      //console.log(hour,'hourhour')
      var min = Math.floor(time / 60) % 60;     //分
      var sec = time % 60;                      //秒
      t = day + '天'
      if (hour < 10) {
        t += '0' + hour + "时";
      } else {
        t += hour + "时";
      }
      if (min < 10) { t += "0"; }
      t += min + "分";
      //console.log(t, 'ttttttttt')
      if (sec < 10) { t += "0"; }
      t += sec      //.toFixed(2);
    }
    //console.log(t, 't')
    that.setData({
      time: t
    })
    set = setInterval(function () {
      if (time == 0){
        clearInterval(set)
        console.log('结束')
      }else{
        let t;
        time = time - 1
        if (time > -1) {
          var day = Math.floor(time / 3600 / 24);     //天
          //console.log(day,'------------')
          var hour = Math.floor(time / 3600) % 24;       //时
          //console.log(hour,'hourhour')
          var min = Math.floor(time / 60) % 60;     //分
          var sec = time % 60;                      //秒
          t = day + '天'
          if (hour < 10) {
            t += '0' + hour + "时";
          } else {
            t += hour + "时";
          }
          if (min < 10) { t += "0"; }
          t += min + "分";
          //console.log(t, 'ttttttttt')
          if (sec < 10) { t += "0"; }
          t += sec      //.toFixed(2);
        }
        //console.log(t, 't')
        that.setData({
          time: t
        })
      }
    }, 1000)
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.request({
      //url: app.data.Url + 'coupon/usercoupon',
      url: app.data.Url + 'spell/SpellGroupGhare',
      data: {
        orderid: options.id
      },
      method: 'get',
      success: function (res) {
        
        console.log('res', res)
        var Numberofpeople = res.data.data.count - res.data.data.headlength;
        //console.log(Numberofpeople,'t人数')
        that.setData({
          content: res.data.data,
          Numberofpeople: Numberofpeople,
          time: res.data.data.spellouttime,
          orderid: options.id
        })
        that.uctime()
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },



  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {
    console.log(e.target.dataset.id)
    if (e.from === 'button') {

      // 来自页面内转发按钮
      console.log(e.target)
    }
    return {
      title: '广电智慧Life小程序',
      path: 'pages/share_purchase/index?id=' + e.target.dataset.id,
      success: function (res) {
        // 转发成功
        wx.showToast({
          title: '分享成功',
        })
        console.log("转发成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        // 转发失败
        wx.showToast({
          title: '分享失败',
        })
        console.log("转发失败:" + JSON.stringify(res));
      }
    }
  },
})